home *** CD-ROM | disk | FTP | other *** search
/ Quick PC 62 / Quick PC 62.iso / I386 / IIS5_01.CAB / IIS_CodeBrws.asp < prev    next >
Encoding:
Text File  |  1999-05-26  |  7.2 KB  |  258 lines

  1. <% Option Explicit %>
  2.  
  3. <HTML>
  4. <HEAD>
  5. <META NAME="DESCRIPTION" CONTENT="ASP Source code browser">
  6. <META NAME="GENERATOR" CONTENT="Microsoft Visual InterDev 1.0">
  7. <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso8859-1">
  8. </HEAD>
  9.  
  10. <BODY  BGCOLOR=#FFFFFF TOPMARGIN=0 LEFTMARGIN=0 ALINK=#23238E VLINK=#808080 LINK=#FFCC00>
  11. <BASEFONT FACE="VERDANA, ARIAL, HELVETICA" SIZE=2>
  12.  
  13. <!-- DISPLAY THE COLOR LEGEND -->
  14. <TABLE BORDER=1>
  15.     <TR>
  16.       <TD WIDTH="25" BGCOLOR="#FF0000">  </TD>
  17.       <TD><FONT FACE="VERDANA, ARIAL, HELVETICA" SIZE="2">ASP Script</FONT></TD>
  18.     </TR>
  19.     <TR>
  20.       <TD BGCOLOR="#0000FF">  </TD>
  21.       <TD><FONT FACE="VERDANA, ARIAL, HELVETICA" SIZE="2">Comments</FONT></TD>
  22.     </TR>
  23.     <TR>
  24.       <TD BGCOLOR="#000000">  </TD>
  25.       <% If InStr(UCase(Request("Source")),".CDX") > 0 Then %>
  26.         <TD><FONT FACE="VERDANA, ARIAL, HELVETICA" SIZE="2">XML and Text</FONT></TD>
  27.       <% Else %>
  28.         <TD><FONT FACE="VERDANA, ARIAL, HELVETICA" SIZE="2">HTML and Text</FONT></TD>
  29.       <% End If %>
  30.     </TR>
  31. </TABLE>
  32.  
  33. <HR>
  34. <FONT FACE="VERDANA, ARIAL, HELVETICA" SIZE="2">
  35.   <% OutputSource %>
  36. </FONT>
  37. </BODY>
  38. </HTML>
  39.  
  40. <SCRIPT LANGUAGE=VBScript RUNAT=Server>
  41.  
  42.  
  43. REM **************************************
  44. REM  intended behavior:
  45. REM allow access to only .asp, .htm, .html, .inc files
  46. REM in some directory starting from /IISSAMPLES
  47. REM and without .. in the path
  48. REM **************************************
  49.  
  50.  FUNCTION fValidPath (ByVal strPath)
  51.   If InStr(1, strPath, "/iissamples/", 1) Then
  52.     ' the beginning of the string looks good
  53.     Dim dwLen
  54.     Dim SomeKnownExtension
  55.     SomeKnownExtension = false
  56.     dwLen = Len(strPath)
  57.     If Not SomeKnownExtension Then
  58.         If InStr(dwLen-5,strPath,".html",1) Then
  59.             SomeKnownExtension = true
  60.         End If
  61.     End If    
  62.     If Not SomeKnownExtension Then
  63.         If InStr(dwLen-4,strPath,".htm",1) Then
  64.            SomeKnownExtension = true 
  65.         End If
  66.     End If
  67.     If Not SomeKnownExtension Then
  68.         If InStr(dwLen-4,strPath,".asp",1) Then
  69.            SomeKnownExtension = true 
  70.         End If
  71.     End If 
  72.     If Not SomeKnownExtension Then
  73.         If InStr(dwLen-4,strPath,".inc",1) Then
  74.            SomeKnownExtension = true 
  75.         End If
  76.     End If     
  77.     If Not SomeKnownExtension Then
  78.         fValidPath = 0
  79.         Exit Function
  80.     End If
  81.     ' now the most importan part: look for ..
  82.     If InStr(1,strPath,"..",1) Then        
  83.         fValidPath = 0
  84.     Else
  85.         fValidPath = 1
  86.     End If
  87.   Else
  88.     fValidPath = 0
  89.   End If
  90.  END FUNCTION
  91. </SCRIPT>
  92.  
  93.  
  94.  
  95. <%
  96.   Sub OutputSource
  97.     Dim strVirtualPath, strFilename
  98.     strVirtualPath = Request("Source")
  99.  
  100.     If fValidPath(strVirtualPath) Then
  101.         strFilename = Server.MapPath(strVirtualPath)
  102.     
  103.         Dim FileObject, oInStream, strOutput
  104.         Set FileObject = CreateObject("Scripting.FileSystemObject")
  105.         Set oInStream = FileObject.OpenTextFile(strFilename, 1, 0, 0)
  106.         While NOT oInStream.AtEndOfStream
  107.           strOutput = oInStream.ReadLine
  108.           Call PrintLine(strOutput, fCheckLine(strOutput))
  109.           Response.Write "<BR>"
  110.         Wend
  111.     Else 
  112.         Response.Write("<H1>View Active Server Page Source-- Access Denied</H1>")
  113.     End If
  114.   End Sub
  115.  
  116.   ' Returns the minimum number greater than 0
  117.   ' If both are 0, returns -1
  118.   Function fMin(iNum1, iNum2)
  119.     If iNum1 = 0 AND iNum2 = 0 Then
  120.       fMin = -1
  121.     ElseIf iNum2 = 0 Then
  122.       fMin = iNum1
  123.     ElseIf iNum1 = 0 Then
  124.       fMin = iNum2
  125.     ElseIf iNum1 < iNum2 Then
  126.       fMin = iNum1
  127.     Else 
  128.       fMin = iNum2
  129.     End If
  130.   End Function
  131.  
  132.   Function fCheckLine (ByVal strLine)
  133.   Dim iTemp, iPos
  134.   fCheckLine = 0
  135.   iTemp = 0
  136.   
  137.   iPos = InStr(strLine, "<" & "%")
  138.   If fMin(iTemp, iPos) = iPos Then
  139.     iTemp = iPos
  140.     fCheckLine = 1
  141.   End If
  142.   
  143.   iPos = InStr(strLine, "%" & ">")
  144.   If fMin(iTemp, iPos) = iPos Then
  145.     iTemp = iPos
  146.     fCheckLine = 2
  147.   End If
  148.   
  149.   iPos = InStr(1, strLine, "<" & "SCRIPT", 1)
  150.   If fMin(iTemp, iPos) = iPos Then
  151.     iTemp = iPos
  152.     fCheckLine = 3
  153.   End If
  154.   
  155.   iPos = InStr(1, strLine, "<" & "/SCRIPT", 1)
  156.   If fMin(iTemp, iPos) = iPos Then
  157.     iTemp = iPos
  158.     fCheckLine = 4
  159.   End If
  160.   
  161.   iPos = InStr(1, strLine, "<" & "!--", 1)
  162.   If fMin(iTemp, iPos) = iPos Then
  163.     iTemp = iPos
  164.     fCheckLine = 5
  165.   End If
  166.   
  167.   iPos = InStr(1, strLine, "-" & "->", 1)
  168.   If fMin(iTemp, iPos) = iPos Then
  169.     iTemp = iPos
  170.     fCheckLine = 6
  171.   End If
  172.   
  173.   End Function
  174.  
  175.   Sub PrintHTML (ByVal strLine)
  176.     Dim iPos, iSpaces, i
  177.     iSpaces = Len(strLine) - Len(LTrim(strLine))
  178.     i = 1
  179.     While Mid(Strline, i, 1) = Chr(9)
  180.       iSpaces = iSpaces + 5
  181.       i = i + 1
  182.     Wend
  183.     If iSpaces > 0 Then
  184.       For i = 1 to iSpaces
  185.         Response.Write(" ")
  186.       Next
  187.     End If
  188.     iPos = InStr(strLine, "<")
  189.     If iPos Then
  190.       Response.Write(Left(strLine, iPos - 1))
  191.       Response.Write("<")
  192.       strLine = Right(strLine, Len(strLine) - iPos)
  193.       Call PrintHTML(strLine)
  194.     Else
  195.       Response.Write(strLine)
  196.     End If
  197.   End Sub
  198.  
  199.   Sub PrintLine (ByVal strLine, iFlag)
  200.     Dim iPos
  201.     Select Case iFlag
  202.       Case 0
  203.         Call PrintHTML(strLine)
  204.       
  205.       Case 1
  206.         iPos = InStr(strLine, "<" & "%")
  207.         Call PrintHTML(Left(strLine, iPos - 1))
  208.         Response.Write("<FONT COLOR=#ff0000>")
  209.         Response.Write("<%")
  210.         strLine = Right(strLine, Len(strLine) - (iPos + 1))
  211.         Call PrintLine(strLine, fCheckLine(strLine))
  212.       
  213.       Case 2
  214.         iPos = InStr(strLine, "%" & ">")
  215.         Call PrintHTML(Left(strLine, iPos -1))
  216.         Response.Write("%>")
  217.         Response.Write("</FONT>")
  218.         strLine = Right(strLine, Len(strLine) - (iPos + 1))
  219.         Call PrintLine(strLine, fCheckLine(strLine))
  220.       
  221.       Case 3
  222.         iPos = InStr(1, strLine, "<" & "SCRIPT", 1)
  223.         Call PrintHTML(Left(strLine, iPos - 1))
  224.         Response.Write("<FONT COLOR=#0000ff>")
  225.         Response.Write("<SCRIPT")
  226.         strLine = Right(strLine, Len(strLine) - (iPos + 6))
  227.         Call PrintLine(strLine, fCheckLine(strLine))
  228.       
  229.       Case 4
  230.         iPos = InStr(1, strLine, "<" & "/SCRIPT>", 1)
  231.         Call PrintHTML(Left(strLine, iPos - 1))
  232.         Response.Write("</SCRIPT>")
  233.         Response.Write("</FONT>")
  234.         strLine = Right(strLine, Len(strLine) - (iPos + 8))
  235.         Call PrintLine(strLine, fCheckLine(strLine))
  236.       
  237.       Case 5
  238.         iPos = InStr(1, strLine, "<" & "!--", 1)
  239.         Call PrintHTML(Left(strLine, iPos - 1))
  240.         Response.Write("<FONT COLOR=#0000ff>")
  241.         Response.Write("<!--")
  242.         strLine = Right(strLine, Len(strLine) - (iPos + 3))
  243.         Call PrintLine(strLine, fCheckLine(strLine))
  244.       
  245.       Case 6
  246.         iPos = InStr(1, strLine, "-" & "->", 1)
  247.         Call PrintHTML(Left(strLine, iPos - 1))
  248.         Response.Write("-->")
  249.         Response.Write("</FONT>")
  250.         strLine = Right(strLine, Len(strLine) - (iPos + 2))
  251.         Call PrintLine(strLine, fCheckLine(strLine))
  252.       
  253.       Case Else
  254.         Response.Write("Function Error -- Please contact the administrator.")
  255.     End Select
  256.   End Sub
  257. %>
  258.